<?php require_once('Connections/tech.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
  $MM_dupKeyRedirect="creat.php";
  $loginUsername = $_POST['username'];
  $LoginRS__query = sprintf("SELECT username FROM customer WHERE username=%s", GetSQLValueString($loginUsername, "text"));
  mysql_select_db($database_tech, $tech);
  $LoginRS=mysql_query($LoginRS__query, $tech) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);

  //if there is a row in the database, the username was found - can not add the requested username
  if($loginFoundUser){
    $MM_qsChar = "?";
    //append the username to the redirect page
    if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
    $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
    header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO customer (username, firstname, lastname, email, password, sex) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['firstname'], "text"),
                       GetSQLValueString($_POST['lastname'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['password'], "int"),
                       GetSQLValueString($_POST['sex'], "text"));

  mysql_select_db($database_tech, $tech);
  $Result1 = mysql_query($insertSQL, $tech) or die(mysql_error());

  $insertGoTo = "login.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DocType html>
<title>
Registration
</title>
<head>
<script type="text/javascript"> 
 
 
 
function notEmpty(elem, helperMsg)
{
	if(elem.value.length == 0)
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
	return true;
}
 
function notEmpty1(elem, helperMsg)
{
	if(elem.value.length == 0)
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
	return true;
}
function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}
 
 
 
function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
 
function choose(elem, helperMsg){
	if(elem.value == "Please Choose your sex"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}
function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}
 
 
</script>
 
</head>
<body bgcolor="#000000">

<form method="POST" action="<?php echo $editFormAction; ?>" name="form1" id="form1">


<table width='70%' border='0' align='center' bgcolor='#980000' height='650' cellpadding='3' cellspacing='3'>
  <tr width='500' height='150'>
    <td  colspan='6' rowspan='1' background='4.jpg'>
    </td>
  </tr>
<td width="35%" align="right">
<font size="5" color="#ffffff"><label>
User Name:
</label></font>
</td>
<td width="65%" align="left"><p>
<input type='text' id='username' name="username"size="50"/>
  </p>
    </td>
    </tr>
<tr width="100%">
<td width="35%" align="right">
<font size="5" color="#ffffff">
First Name:
</font>
</td>
<td width="65%" align="left"><p>
<input type='text' id='firstname' name="firstname"size="50"/>
</p>
</td>
</tr>
<tr width="100%">
<td width="35%" align="right">
<font size="5" color="#ffffff">
Last Name:
</font>
</td>
<td width="65%" align="left">
<input type='text' id='lastname' name="lastname"size="50"/>
</td>
</tr>
<tr width="100%">
<td width="35%" align="right">
<font size="5" color="#ffffff">
Your Email:
</font>
</td>
<td width="65%" align="left">
<input type='email' id='email' name="email" size="50"/>
</td>
</tr>
<tr width="100%">
<td width="35%" align="right">
<font size="5" color="#ffffff">
Password:
</font>
</td>
<td width="65%" align="left">
<input type="password" id='password' name="password" size="50"/>
</td>
</tr>
<tr width="100%">
<td width="35%" align="right" >
<font size="5" color="#ffffff">
Sex:
</font>
</td>
<td width="65%" align="left">
<input type="radio" name="sex" value="male" id="choose" /> 
<font size="5" color="#ffffff">
Male
</font>
<br />
<input type="radio" name="sex" value="female" />
<font size="5" color="#ffffff"> 
Female
</font>

 
 
</td>
</tr>
<tr width="100%">
<td width="35%" align="right">
<font size="5" color="#ffffff">
Birthday:
</font>
</td>
<td width="65%" align="left">
<select id="selection" title="-Select Day-">
                              <option title="-Select Day-" value="" selected>-Select Day-</option>
							    <option title="1" value="1">1</option>
								<option title="2" value="2">2</option>
								<option title="3" value="3">3</option>
								<option title="4" value="4">4</option>
								<option title="5" value="5">5</option>
								<option title="6" value="6">6</option>
								<option title="7" value="7">7</option>
								<option title="8" value="8">8</option>
								<option title="9" value="9">9</option>
								<option title="10" value="10">10</option>
								<option title="11" value="11">11</option>
								<option title="12" value="12">12</option>
								<option title="13" value="13">13</option>
								<option title="14" value="14">14</option>
								<option title="15" value="15">15</option>
								<option title="16" value="16">16</option>
								<option title="17" value="17">17</option>
								<option title="18" value="18">18</option>
								<option title="19" value="19">19</option>
								<option title="20" value="20">20</option>
								<option title="21" value="21">21</option>
								<option title="22" value="22">22</option>
								<option title="23" value="23">23</option>
								<option title="24" value="24">24</option>
								<option title="25" value="25">25</option>
								<option title="26" value="26">26</option>
								<option title="27" value="27">27</option>
								<option title="28" value="28">28</option>
								<option title="29" value="29">29</option>
								<option title="30" value="30">30</option>
								<option title="31" value="31">31</option>
</select>

								
<select title="- Select Month -" >
                              <option title="- Select Month -" value="" SELECTED >- Select Month -</option>
                              <option title="January" value="1" >January</option>
                              <option title="February" value="2"  >February</option>
                              <option title="March" value="3"  >March</option>
                              <option title="April" value="4"  >April</option>
                              <option title="May" value="5"  >May</option>
                              <option title="June" value="6"  >June</option>
                              <option title="July" value="7"  >July</option>
                              <option title="August" value="8"  >August</option>
                              <option title="September" value="9"  >September</option>
                              <option title="October" value="10"  >October</option>
                              <option title="November" value="11"  >November</option>
                              <option title="December" value="12"  >December</option>
</select>
<input title="Year" type="text"  size="10%">
</td>
</tr>
<tr>
<td width="35%" align="right">
<font size="5" color="#ffffff">
Country:
</font>
</td>
<td width="65%" align="left">
<select title="-Select Country-">
                              <option title="-Select country-" value="" selected>-Select country-</option>
							    <option  value="Afghanistan1">Afghanistan</option>
								<option  value="Argentina">Argentina</option>
								<option  value="Bahrain">Bahrain</option>
								<option  value="Brazil">Brazil</option>
								<option value="China">China</option>
								<option  value="Colombia">Colombia</option>
								<option  value="Denmark">Denmark</option>
								<option  value="Ecuador">Ecuador</option>
								<option value="Egypt">Egypt</option>
								<option value="France">France</option>
								<option value="Germany">Germany</option>
								<option value="Ghana">Ghana</option>
								<option value="Hong Kong">Hong Kong</option>
								<option value="India">India</option>
								<option value="Japan">Japan</option>
								<option value="Kenya">Kenya</option>
								<option value="Kuwait">Kuwait</option>
								<option value="Lebanon">Lebanon</option>
								<option value="Mali">Mali</option>
								<option value="Mexico">Mexico</option>
								<option value="Netherlands">Netherlands</option>
								<option value="Oman">Oman</option>
								<option value="Peru">Peru</option>
								<option value="Qatar">Qatar</option>
								<option value="Russia">Russia</option>
								<option value="Saudi Arabia">Saudi Arabia</option>
								<option value="Spain">Spain</option>
								<option value="United States">United States</option>
								<option value="Yemen">Yemen</option>
								<option value="Zambia">Zambia</option>
								<option value="Zimbabwe">Zimbabwe</option>
</select>
</td>
</tr>
<tr width="100%">
<td width="35%" align="right">
<input type="checkbox" value="yes"/>
</td>>
<tr width="100%" >
<td colspan="2" align="center">
<input name="submit" type="submit" id="submit" value="register"  />
<input type="hidden" name="MM_insert" value="form1">

</td>
</tr>
>

</table>

</form>

</body>

</html>

